package com.tushu.view;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;

import com.tushu.model.Student;
import com.tushu.utils.TimeTools;
import com.tushu.view.common.Setting;
import com.tushu.view.common.Welcome;
import com.tushu.view.student.LendBook;
import com.tushu.view.student.SearchBook;

import javax.swing.JButton;
import java.awt.CardLayout;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.awt.event.ActionEvent;
import javax.swing.border.TitledBorder;
import javax.swing.JLabel;
import java.awt.Font;

public class StuWin extends JFrame {

	private JPanel contentPane;
	
	CardLayout cardLayout=new CardLayout();
	
	JPanel panel ;
	
	String account;
	private  JLabel jl1 = new JLabel("");

	/**
	 * Create the frame.
	 * @throws SQLException 
	 */
	public StuWin(Student student) throws SQLException {
		this.account=student.getAccount();
		
		try {
			UIManager.setLookAndFeel(   UIManager.getSystemLookAndFeelClassName()); 
		} catch (Exception e) {
			// TODO: handle exception
		}
		jl1.setFont(new Font("宋体", Font.PLAIN, 15));
		jl1.setText("你好 "+student.getName());
		setTitle("\u501F\u9605\u7CFB\u7EDF");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 564, 435);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JButton jb1 = new JButton("\u68C0\u7D22");
		jb1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				cardLayout.show(panel,"search");
			}
		});
		jb1.setBounds(115, 21, 81, 23);
		contentPane.add(jb1);
		
		JButton jb2 = new JButton("\u501F/\u8FD8\u4E66");

		jb2.setBounds(218, 21, 91, 23);
		contentPane.add(jb2);
		
		JButton jb4 = new JButton("\u4E2A\u4EBA\u4FE1\u606F");
		jb4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				cardLayout.show(panel, "setting");
			}
		});
		jb4.setBounds(328, 21, 91, 23);
		contentPane.add(jb4);
		
		panel = new JPanel();
		panel.setBorder(new TitledBorder(null, "\u64CD\u4F5C\u6846", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel.setBounds(10, 54, 535, 321);
		contentPane.add(panel);
		panel.setLayout(cardLayout);

		panel.add(new SearchBook(),"search");
		panel.add(new Setting(student),"setting");
		panel.add(new LendBook(student),"lendbook");
		panel.add(new Welcome(),"welcome");
		cardLayout.show(panel, "welcome");
		
		
		JButton btnNewButton = new JButton("\u9000\u51FA");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.out.println("退出");
			}
		});
		btnNewButton.setBounds(441, 21, 91, 23);
		contentPane.add(btnNewButton);
		
		JButton jb1_1 = new JButton("\u9996\u9875");
		jb1_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				cardLayout.show(panel, "welcome");
			}
		});
		
		jb2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				cardLayout.show(panel, "lendbook");
			}
		});
		jb1_1.setBounds(16, 21, 74, 23);
		contentPane.add(jb1_1);
		jl1.setBounds(20, 373, 135, 36);
		contentPane.add(jl1);
		
		JLabel jl2 = new JLabel("");
		jl2.setFont(new Font("宋体", Font.PLAIN, 15));
		jl2.setText(TimeTools.getTime3());
		jl2.setBounds(441, 384, 126, 15);
		contentPane.add(jl2);
	}
}
